<?php
/**
 * 访问所有接口的关口
 * @author solar
 */

class Gateway 
{
	public static function excute($method,$class,$module='default') {
		$proxy=ProxyFactory::get($class,$module);
		if($proxy===false || !method_exists($proxy,$method)) return array('ikylin'=>self::NotFound);
		if(self::checkAuth($proxy,$method)===false) return array('ikylin'=>self::Unauthorized);
		return $proxy->$method();
	}
	
	public static function checkAuth($proxy,$method) {
		if(in_array($method,$proxy->noAuthMethod())) return true;
		require_once PATH_API.'/service/UserService.php';
		if(UserService::isLogined()) return true;
		return false;
	}
	
	const NotFound=404;
	const Unauthorized=401; 
}

?>